function LinkedListCycle() {}

LinkedListCycle.isCycle = function(head) {
    var p1 = head;
    var p2 = head;
    while (p2!=null && p2.next!=null){
        p1 = p1.next;
        p2 = p2.next.next;
        if(p1 == p2){
            return true;
        }
    }
    return false;
};
 
function Node(data) {
    this.data = data;
    this.next = null;
};

var node1 = new Node(5);
var node2 = new Node(3);
var node3 = new Node(7);
var node4 = new Node(2);
var node5 = new Node(6);
node1.next = node2;
node2.next = node3;
node3.next = node4;
node4.next = node5;
node5.next = node2;

console.log(LinkedListCycle.isCycle(node1));